import { FormControl, FormGroup, FormArray } from '@angular/forms';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'search-form',
  templateUrl: './search-form.component.html',
  styleUrls: ['./search-form.component.css']
})
export class SearchFormComponent{
  form = new FormGroup({
    searches: new FormArray([])
  });

  get searches() {
    return this.form.get('searches') as FormArray;
  }
  addSearch(search: HTMLInputElement) {
    this.searches.push(new FormControl(search.value));
    search.value = '';
  }
  removeSearch(search: FormControl) {
    let index = this.searches.controls.indexOf(search);
    console.log(index);
    this.searches.removeAt(index);
  }
}
